package com.jevons.geo_lib.geojson.adapter;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.CoordinateContainer;
import com.mapbox.geojson.Point;

import java.io.IOException;
import java.util.List;

/**
 * Copyright 2020 JxGIS
 *
 * @file PointGsonTypeAdapter
 * @auth linaisheng
 * Created on 2022/7/13.
 * Description：
 */
final class PointTypeAdapter extends BaseGeometryTypeAdapter<Point, List<Double>> {

    PointTypeAdapter(Gson gson) {
        super(gson, new ListOfDoublesCoordinatesTypeAdapter());
    }

    @Override
    @SuppressWarnings("unchecked")
    public void write(JsonWriter jsonWriter, Point object) throws IOException {
        writeCoordinateContainer(jsonWriter, object);
    }

    @Override
    @SuppressWarnings("unchecked")
    public Point read(JsonReader jsonReader) throws IOException {
        return (Point)readCoordinateContainer(jsonReader);
    }

    @Override
    CoordinateContainer<List<Double>> createCoordinateContainer(String type,
                                                                BoundingBox bbox,
                                                                List<Double> coordinates) {
        return Point.fromLngLat(coordinates.get(0), coordinates.get(1), bbox);
    }
}